<!DOCTYPE html>
<html>

<head>
    <head/>
    <title>医院详情</title>
    <titleType style="display: none;">sc</titleType>
    <%- include('./_global/appendJs') %>
        <script src="/static/lib/forweb.js"></script>
        <script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
        <script src="/static/js/<%=type%>/pageUrl.js"></script>
        <script src="/static/js/<%=type%>/yygh.js"></script>
</head>
<style>
    html,body {
        overflow: hidden;
    }
    .hospital-detail .hospital-jj-box .text-box span.yellow {
        margin-left: 0.5rem !important;
    }
    .hospital-detail .box-left dl dd {
        height: auto;
        padding-bottom: 15rem;
    }
    .hospital-detail .box-left {
        overflow: auto;
    }
    .hospital-detail .box-right {
        overflow: auto;
    }
    .tab { 
        height: 100%;
    }
    #ListTabBox {
        height: 80vh;
    }
    .hospital-detail .box-left dl dd a {
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .hospital-detail .pbks-box tbody tr th:first-child {
        font-size: 1.4rem;
    }
    .hospital-detail .pbks-box tbody tr th:nth-child(2) {
        text-align: left;
        padding-left: 0.8rem;
        font-size: 1.1rem;
    }

</style>


<body>
    <input id="titleType" type="hidden" value="sc">
    <section class="page-wrap hospital-detail">
        <!-- <header class="header-box grey fixed">
            <div class="header-content">
                <div class="left-tool">
                    <a class="back" href="javascript:void(0);">
                        <i class="iconfont icon-back"></i>
                    </a>
                </div>
                <div class="right-tool">
                <a href="javascript:void(0);"><i class="sc-icon"></i></a>
            </div>
                <div class="title">医院详情</div>
            </div>
        </header> -->
        <div class="hospital-jj-box" id="hosDiv">
            <i class="icon-box hosImgUrl"></i>
            <div class="text-box">
                <span class="title hosName"></span>
                <span class="yellow hosLevel"></span>
                <span class="yellow isMedicare"></span>
                <!-- <span class="doctorCount"></span> -->
                <span class="hosAddress"></span>
            </div>
            <!-- <a class="ck-map" href="javascript:void(0)">查看地图</a> -->
        </div>
        <div class="hospital-tab-box">
            <ul class="row" id="ListTab">
                <li class="col-xs-4 active" index="0">
                    <a>预约挂号</a>
                </li>
                <li class="col-xs-4" index="1">
                    <a>医院简介</a>
                </li>
                 <li class="col-xs-4" index="2">
                    <a>预约规则</a>
                </li>
            </ul>
        </div>
        <div id="ListTabBox">
            <div class="tab active clearfix" index="0">
                <div class="box-left">
                    <dl>
                        <dd>
                        </dd>
                    </dl>
                </div>
                <div class="box-right">
                    <ul>
                    </ul>
                </div>
            </div>
            <div class="tab" style="display:none;" index="1">
                <div class="hospital-text-box">
                </div>
            </div>
            <div class="tab" style="display:none;" index="2">
                <table class="pbks-box">
                    <tr>
                        <th class="first-th">详情</th>
                        <th>
                            <h3>预约规则</h3>
                            <p>预约周期：14天</p>
                            <p>退号时间：就诊前一工作日14点前取消</p>
                        </th>
                        <!-- <th>下午（13:30-17:00）</th> -->
                    </tr>

                </table>
            </div>
        </div>
    </section>
</body>
<script type="text/html" id="ksLi">
    <li>
        <a href="javascript:void(0);"></a>
    </li>
</script>
<script type="text/html" id="pbxxOne">
    <tr>
        <td class="odd-week date"></td>
        <td class="AM"></td>
        <td class="PM"></td>
    </tr>
</script>
<script type="text/html" id="pbxxTwo">
    <tr>
        <td class="even-week date"></td>
        <td class="even-content AM"></td>
        <td class="even-content PM"></td>
    </tr>
</script>
<script type="text/javascript">
    var page_hosDetail = (function ($, page_hosDetail) {

        var tb_zy_yyjb = {
            "0": "社区卫生服务中心",
            "1": "一级",
            "2": "二级",
            "3": "三级",
            "": "未评级"
        };
        var tb_zy_yydj = {
            "0": "特等",
            "1": "甲等",
            "2": "乙等",
            "3": "丙等",
            "4" : "合格"
        };
        var tb_zy_hosType = {
            "1" : "综合性医院",
            "2" : "专科医院",
            "3" : "中医医院",
            "4" : "专科疾病防治所(站，中心)",
            "5" : "妇幼保健院(所，站)"
        };

        var sfsc = "";
        var requestRoot = "/jkcsHt/yygh";
        var hosCode = $.QuickUrlUtils.getRequest("hosCode");

        /**加载视图*/
        function initView() {
            /**一级科室点击*/
            $(".box-left").on("click", "a", function () {
                /**脚本改变选中状态*/
                if (!$(this).hasClass("active")) {
                    $(".box-right").show();
                    $(this).addClass("active").siblings().removeClass("active");
                }
                var info = $(this).data("info");
                /**查询二级科室*/
                // $.QuickRemote.AjaxJson({
                //     funcName: $.getMyorderUrl.getpageUrl("getDeptListTwo"),
                //     callback: function (result) {
                //         /**解析二级科室*/
                //         var data = result;
                //         var lis = [];
                //         $(data).each(function (index, item) {
                //             var ks = $($("#ksLi").html());
                //             $(ks).find("a").html(item["depName"]);
                //             $(ks).data("info", item);
                //             lis.push(ks);
                //         });
                //         var ul = $(".box-right").find("ul");
                //         $(ul).empty();
                //         $(ul).append(lis);
                //     },
                //     params: {
                //         hosCode: hosCode,
                //         oneDepCode: info["depCode"]
                //     }
                // });
                var params = {
                    hosCode: hosCode,
                    oneDepCode: info["depCode"],
                    parentCode : info["parentCode"]
                }
                $.ajax({
                    type: "POST", // 使用get方法访问后台
                    dataType: "json", // 返回json格式的数据
                    "headers": {
                        "Content-Type": "application/json",
                        "Cache-Control": "no-cache",
                    },
                    url: "/api/yyghAdapter/getDeptListTwo.service", // 要访问的后台地址
                    data: JSON.stringify(params), // 要发送的数据
                    success: function (data) {
                       
                        var ul = $(".box-right").find("ul");
                        $(ul).empty();
                        if (data.code == "SUCCESS") {
                            if (data && data.data && data.data.length > 0) {
                                 /**解析二级科室*/
                                var data = data.data;
                                var lis = [];
                                $(data).each(function (index, item) {
                                    var ks = $($("#ksLi").html());
                                    $(ks).find("a").html(item["depName"]);
                                    $(ks).data("info", item);
                                    lis.push(ks);
                                });
                                
                                $(ul).append(lis);
                            }
                        } else {
                            $.QuickAlert.alertFail({
                                content: data.message
                            });
                        }
                    }
                });
            });

            /**二级科室点击跳转*/
            $(".box-right").on("click", "li", function () {
                var info = $(this).data("info");
                StoreCache.setCache("YYGH_KSINFO", info);
                $.pageSwitch.goToUrl("myOrder", "ksDetailList");
            });

            /**医院信息table切换*/
            $("#ListTab").on("click", "li", function () {
                if (!$(this).hasClass("active")) {
                    $(this).addClass("active").siblings().removeClass("active");
                }
                var index = $(this).attr("index");
                $("#ListTabBox").find(".tab").hide();
                $("#ListTabBox").find(".tab[index='" + index + "']").show();
            });

            /**获取跳转路径参数判断tab切换*/
            var tab = $.QuickUrlUtils.getRequest("HOSDETAIL_TAB");
            if (!StringUtils.isEmpty(tab)) {
                $("#ListTab").find("li[index='" + tab + "']").trigger("click");
            }
            /**收藏按钮*/
            $(".sc-icon").on("click", page_hosDetail.scFunction);
            /**设置收藏使用参数*/
            $(".sc-icon").data("info", {
                hosCode: hosCode
            });
            $.JkcsUtils.jsbridgeRegister("scFunction", page_hosDetail.scFunction);

        }

        /**加载数据*/
        function initData() {
            page_hosDetail.getHospitalList();
            page_hosDetail.getDeptListTop();
        }

        function getHospitalList() {
            var params = {
                "districtCode": "",
                "hoscode": hosCode,
                "hosname": "",
                "pageNum": 1,
                "pageSize": 10
            }
            // $.QuickRemote.AjaxJson({
            //     funcName: ""
            //     ,callback: page_hosDetail.getHospitalListHandler
            //     ,params:{hosCode: hosCode}
            // });
            $.ajax({
                type: "POST", // 使用get方法访问后台
                dataType: "json", // 返回json格式的数据
                "headers": {
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache",
                },
                url: "/api/yyghAdapter/getHospital.service", // 要访问的后台地址
                data: JSON.stringify(params), // 要发送的数据
                success: function (data) {
                    if (data.code == "SUCCESS") {
                        page_hosDetail.getHospitalListHandler(data.data);
                    } else {
                        $.QuickAlert.alertFail({
                            content: data.message
                        });
                    }
                }
            });
        }

        function getHospitalListHandler(result) {
            var hospitals = result['hospitals'];
            if (result && result['hospitals'] && hospitals.length > 0) {
                var hosInfo = hospitals[0];
                $('body').data('hosInfo', hosInfo);
                StoreCache.setCache("YYGH_HOSINFO", hosInfo);
                page_hosDetail.setHosInfo();
            }
        }
        /*设置医院信息*/
        function setHosInfo() {
            var hosInfo = $('body').data('hosInfo');
            var hosDiv = $("#hosDiv");
            var hosImgUrl = hosInfo["hosImgUrl"];
            if (!StringUtils.isEmpty(hosImgUrl)) {
                hosDiv.find(".hosImgUrl").attr("style", "background:url('" + hosInfo["hosImgUrl"] +
                    "') no-repeat;background-size: 100% 100%;");
            }
            hosDiv.find(".hosName").text(hosInfo["hosName"]);
            var hosGrade = hosInfo["hosGrade"];
            var hosLevel = hosInfo["hosLevel"];

            hosDiv.find(".hosLevel").text(tb_zy_yyjb[hosGrade] + tb_zy_yydj[hosLevel]);
             hosDiv.find(".isMedicare").text(tb_zy_hosType[hosInfo["hospitalType"]]);
            //  hosDiv.find(".doctorCount").text((hosInfo["doctorCount"] == "" ? "0" : hosInfo["doctorCount"]) + " 医生");
            hosDiv.find(".hosAddress").text("地址：" + hosInfo["hosAddress"]);
            hosDiv.find(".ck-map").on("click", function () {
                var str = hosInfo["hosLocation"];
                if (str) {
                    var strs = str.split(",");
                    var params = {
                        longitude: strs[0],
                        latitude: strs[1],
                        hosName: hosInfo["hosName"]
                    };
                    $.JkcsUtils.gotoMap(params);
                }
            });
            /**添加医院简介*/
            var yyjj = $("<p>").html(hosInfo["hosDesc"]);
            $(".hospital-text-box").append(yyjj);
        }

        function getDeptListTop() {
            // $.QuickRemote.AjaxJson({
            //     funcName: $.getMyorderUrl.getpageUrl("getDeptListTop"),
            //     callback: function (result) {
            //         /**解析一级科室*/
            //         var data = result;
            //         var lis = [];
            //         $(data).each(function (index, item) {
            //             var ks = $("<a>").attr("href", "javascript:void(0);");
            //             $(ks).html(item["depName"]);
            //             $(ks).data("info", item);
            //             lis.push(ks);
            //         });
            //         var dd = $(".box-left").find("dd");
            //         $(dd).empty();
            //         $(dd).append(lis);
            //         $(dd).find("a:eq(0)").trigger("click");
            //     },
            //     params: {
            //         hosCode: hosCode
            //     }
            // });
            var params = {
                hosCode: hosCode
            };
            $.ajax({
                type: "POST", // 使用get方法访问后台
                dataType: "json", // 返回json格式的数据
                "headers": {
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache",
                },
                url: "/api/yyghAdapter/getDeptListTop.service?hosCode=" + hosCode, // 要访问的后台地址
                // data: params, // 要发送的数据
                success: function (data) {
                    if (data.code == "SUCCESS") {
                        /**解析一级科室*/
                        if (data.data && data.data.length > 0) {
                            var data = data.data;
                            var lis = [];
                            $(data).each(function (index, item) {
                                var ks = $("<a>").attr("href", "javascript:void(0);");
                                $(ks).html(item["depName"]);
                                $(ks).data("info", item);
                                lis.push(ks);
                            });
                            var dd = $(".box-left").find("dd");
                            $(dd).empty();
                            $(dd).append(lis);
                            $(dd).find("a:eq(0)").trigger("click");
                        }
                    } else {
                        $.QuickAlert.alertFail({
                            content: data.message
                        });
                    }
                }
            });
        }

        /**收藏方法*/
        function scFunction() {
            var params = $(".sc-icon").data("info");
            params["sfsc"] = sfsc;
            $.QuickRemote.AjaxJson({
                funcName: "/api" + requestRoot + "/saveYyscInfo",
                callback: function (result) {
                    if (result["code"] == "0") {
                        if (sfsc == 0) {
                            sfsc = 1;
                        } else {
                            sfsc = 0;
                        }
                        page_hosDetail.loadScImg();
                    } else {
                        var content = "";
                        if (sfsc == 0) {
                            content = "收藏医院失败！";
                        } else {
                            content = "取消收藏医院失败！";
                        }
                        $.QuickAlert.alertFail({
                            content: content
                        });
                    }
                },
                params: params
            });
        }

        /**加载收藏图片*/
        function loadScImg() {
            $.JkcsUtils.loadScImg(sfsc);
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            getHospitalList: getHospitalList,
            getHospitalListHandler: getHospitalListHandler,
            setHosInfo: setHosInfo,
            getDeptListTop: getDeptListTop,
            scFunction: scFunction,
            loadScImg: loadScImg,
        }

        page_hosDetail.init = function (cfg) {
            $.extend(page_hosDetail, cfg_def, cfg);
            page_hosDetail.initData();
            page_hosDetail.initView();

        }

        return page_hosDetail;
    })(jQuery, {});
</script>

</html>